import axios from "./request";
import { IErrorData, ISuccessData, ISuccessPageData } from "./returnData";

/**
 * 项目数据约束
 */
export interface IProjectObj {
    description: string[] | string,
    name: string,
    url: string,
    github: string,
    thumb: string,
    order: number,
    id?: string
}

export interface IProjectData {
    rows: IProjectObj[],
    total: number
}

/**
 * 获取项目
 * @returns 
 */
export function getProject(): Promise<ISuccessPageData<IProjectData> | IErrorData> {
    return axios.get('/api/project');
}

/**
 * 修改项目
 * @param id 项目id值 
 * @param project 修改的内容
 * @returns 
 */
export function updateProject(id: string, project: IProjectObj): Promise<ISuccessData<IProjectData> | IErrorData> {
    return axios.put(`/api/project/${id}`, project)
}

/**
 * 添加项目
 * @param project 项目的内容 
 * @returns 
 */
export function addProject(project: IProjectObj): Promise<ISuccessData<IProjectObj> | IErrorData> {
    return axios.post('/api/project', project)
}

/**
 * 删除项目
 * @param id id值
 * @returns 
 */
export function deleteProject(id: string): Promise<ISuccessPageData<boolean> | IErrorData> {
    return axios.delete(`/api/project/${id}`)
}